<?php

namespace App\Http\Controllers;

use App\Exceptions\Code\ErrorCode;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function success($data = [], $message = '成功', $errCode = ErrorCode::SUCCESS, $statusCode = 200)
    {
        $content = [
            'errcode' => $errCode,
            'errmsg' => $message,
            'data' => $data
        ];
        return response()->json($content, $statusCode, [], JSON_UNESCAPED_UNICODE);
    }

    public function successObject($data = [], $message = 'ok', $errCode = ErrorCode::SUCCESS, $statusCode = 200)
    {
        if (empty($data)) {
            $data = new \stdClass();
        }
        $this->success($data, $message, $errCode, $statusCode);
    }

}
